//
//  FTSmartAccount.m
//  FotileStyle
//
//  Created by NB1539 on 2017/9/8.
//  Copyright © 2017年 Fotile. All rights reserved.
//

#import "FTSmartAccount.h"

@implementation FTSmartAccount
/// 返回一个 Dict，将 Model 属性名对映射到 JSON 的 Key。
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{
             @"accessToken":@"access_token",
             @"refreshToken":@"refresh_token",
             @"expireIn":@"expire_in",
             @"userId":@"user_id",
             };
}
- (void)setExpireIn:(NSNumber *)expireIn {
    _expireIn = expireIn;
    _expireDate = [NSDate dateWithTimeIntervalSinceNow:expireIn.doubleValue];
}
/**
 *  当一个对象要归档进沙盒中时，就会调用这个方法
 *  目的：在这个方法中说明这个对象的哪些属性要存进沙盒
 */

-(void)encodeWithCoder:(NSCoder *)aCoder {
    
    [aCoder encodeObject:self.accessToken forKey:@"access_token"];
    [aCoder encodeObject:self.userId forKey:@"user_id"];
    [aCoder encodeObject:self.expireIn forKey:@"expire_in"];
    [aCoder encodeObject:self.refreshToken forKey:@"refresh_token"];
    [aCoder encodeObject:self.expireDate forKey:@"expire_date"];
    [aCoder encodeObject:self.authorize forKey:@"authorize"];
    
}


/**
 *  当从沙盒中解档一个对象时（从沙盒中加载一个对象时），就会调用这个方法
 *  目的：在这个方法中说明沙盒中的属性该怎么解析（需要取出哪些属性）
 */

-(id)initWithCoder:(NSCoder *)aDecoder {
    
    if (self = [super init]) {
        
        self.accessToken = [aDecoder decodeObjectForKey:@"access_token"];
        self.userId = [aDecoder decodeObjectForKey:@"user_id"];
        self.expireIn = [aDecoder decodeObjectForKey:@"expire_in"];
        self.refreshToken = [aDecoder decodeObjectForKey:@"refresh_token"];
        self.expireDate = [aDecoder decodeObjectForKey:@"expire_date"];
        self.authorize = [aDecoder decodeObjectForKey:@"authorize"];
        
    }
    
    return self;
}
@end
